package com.xhs.constant;

import cn.hutool.core.util.StrUtil;

/**
 * @desc: redis 的key枚举类
 * @projectName: spring-boot-redis
 * @author: xhs
 * @date: 2024-06-23 023 16:05
 * @version: JDK 1.8
 */
public enum RedisKeyEnum {

    // 用户编码
    USER_STRING("CODE", "STRING", "用户编码"),
    // 用户列表
    USER_LIST("USER", "LIST", "用户列表"),
    // 用户信息
    USER_MAP("USER", "MAP", "用户信息"),

    ;

    /**
     * 分隔符
     */
    public static final String JOIN_COLON = ":";

    /**
     * 对应的表名
     */
    private String table;

    /**
     * 对应的类型
     */
    private String type;

    /**
     * 描述
     */
    private String desc;

    public String desc() {
        return desc;
    }

    RedisKeyEnum(String table, String type, String desc) {
        this.table = table;
        this.type = type;
        this.desc = desc;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        String sysCode = "3";
        sb.append("XHS:REDIS").append(JOIN_COLON)
                .append(table);
        if (StrUtil.isNotBlank(type)) {
            sb.append(JOIN_COLON)
                    .append(type);
        }
        return sb.toString();
    }

    /**
     * 拼接字符串
     *
     * @param other
     * @return String
     */
    public String append(String... other) {
        StringBuffer sb = new StringBuffer(toString());
        for (String s : other) {
            sb.append(JOIN_COLON).append(s);
        }
        return sb.toString();
    }
}
